package gruppe7.model;

import java.util.List;

import gruppe7.model.db.MySQLDataProvider;


public class Model implements DataProvider {

	private static Model instance = new Model();
	
	public static Model getInstance() {
		return instance;
	}
	
	private DataProvider dataProvider = null;
	
	
	public Model() {
		dataProvider = new MySQLDataProvider();	
	}
	
	public int getFantoms(int zones) {

        if (zones <= 2) {
            return 200;
        } else if (zones <= 4) {
            return 300;
        } else if (zones <= 6) {
            return 450;
        } else if (zones < 9) {
            return 500;
        } else {
            return 577;
        }
    }
	
	public boolean buyTicket(User user, float price) throws ProviderException {
		
		float balance = user.getBalance();
		
		if (balance > price) {
			updateUserBalance(user, balance - price);
			return true;
		}
		
		else return false;
	}
	
	@Override
	public User getUserByName(String username) throws UserException, ProviderException {
		return dataProvider.getUserByName(username);
	}

	@Override
	public void updateUserBalance(User user, float newBalance) throws ProviderException {
		dataProvider.updateUserBalance(user, newBalance);
		user.setBalance(newBalance);
	}

	@Override
	public Station getStationByName(String name) throws ProviderException {
		return dataProvider.getStationByName(name);
	}

	@Override
	public List<String> getStationList() throws ProviderException {
		return dataProvider.getStationList();
	}

	@Override
	public void updateStationInfo(Station station, String newName, int newZone,
			String newManager, String newDate, String newComment)
			throws ProviderException {
		
		dataProvider.updateStationInfo(station, newName, newZone, newManager, newDate, newComment);
	}

	@Override
	public User[] getAllUsers() throws ProviderException {
		return dataProvider.getAllUsers();
	}

	@Override
	public User getUserById(int userId) throws ProviderException, UserException {
		return dataProvider.getUserById(userId);
	}

	@Override
	public String getManagerByStationId(int stationID) throws ProviderException {
		return dataProvider.getManagerByStationId(stationID);
	}
}
